import com.google.common.io.ByteStreams;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.InputStream;
import java.net.URI;

/**
 * @author pengjunzhe
 */
public class ReadRemoteHdfs {
    public static void main(String[] args) throws Exception {
        String uri = "hdfs://192.168.132.238:8020/test/FlumeData.1545297469678.hdfs";
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(uri), conf);
        try (InputStream in = fs.open(new Path(uri))) {
            String str = new String(ByteStreams.toByteArray(in));
            System.out.println(str);
            //((FSDataInputStream) in).seek(0);
            //IOUtils.copy(in, System.out);
        }
    }
}
